<template>
  <!-- 基于 Element UI 新增和修改弹窗 -->
  <a-drawer
    :title="!dataForm.id ? '添加' : '举报'"
    :visible="visible"
    @close="cancel"
    :body-style="{ paddingBottom: '80px' }"
    :width="1000"
  >
    <!-- 新增和创建表单表单 -->
    <el-form :model="dataForm" :rules="dataRule" v-loading="loading" ref="dataForm" @keyup.enter.native="dataSubmit()"
             label-width="80px" style="padding: 0px 10px;margin: 0px 10px">
      <el-form-item label="举报图片">
        <el-image style="width: 180px !important;height: 100% !important"  fit="scaleDown" v-for="item in dataForm.imgurl.split(',')" :src="item" :preview-src-list="[item]"/>
      </el-form-item>
      <el-form-item label="举报内容">
        <a-textarea :rows="4" v-model="dataForm.content" placeholder="请输入内容"/>
      </el-form-item>
      <el-form-item label="回复内容">
        <a-textarea :rows="4" v-model="dataForm.replycontent" placeholder="请输入回复内容"/>
      </el-form-item>
    </el-form>
    <div
      :style="{position: 'absolute',right: 0,bottom: 0,width: '100%', borderTop: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',textAlign: 'right',zIndex: 1,}">
      <el-button @click="cancel()" :style="{ marginRight: '8px' }">取消</el-button>
      <el-button type="primary" @click="submit()">确定</el-button>
    </div>
  </a-drawer>
</template>

<script>
import api from '@/api/api'

export default {
  components: {},
  data() {
    return {
      visible: false,
      selOptions: {},
      loading: false,
      dataForm: {
        id: 0,
        imgurl: '',
        content: '',
        replycontent: '',
        type: '',
        oid: '',
        otype: '',
        userid: '',
        username: '',
        status: '',
        createtime: '',
        updatetime: ''
      },
      dataRule: {
        imgurl: [
          { required: true, message: '举报图片  为必填项', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '举报内容  为必填项', trigger: 'blur' }
        ],
        replycontent: [
          { required: true, message: '回复内容  为必填项', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '举报类型  为必填项', trigger: 'blur' }
        ],
        oid: [
          { required: true, message: '举报ID  为必填项', trigger: 'blur' }
        ],
        otype: [
          { required: true, message: '举报ID类型  为必填项', trigger: 'blur' }
        ],
        userid: [
          { required: true, message: '举报人  为必填项', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '举报人名称  为必填项', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '状态：0  为必填项', trigger: 'blur' }
        ],
        createtime: [
          { required: true, message: '创建日期  为必填项', trigger: 'blur' }
        ],
        updatetime: [
          { required: true, message: '更新时间  为必填项', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(id) { // 初始化表单验证规则
      this.dataForm.id = id || undefined
      this.visible = true
      this.selOptions = this.$constants.selOptions
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.loading = true
          api.post('rest/vabc/tipoff/info', { id: this.dataForm.id }).then(res => {
            this.dataForm = res
          }).finally(() => {
            this.loading = false
          })
        }
      })
    },
    // 表单数据提交
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          let postData = Object.assign({}, this.dataForm)
          if (!this.dataForm.id) {
            postData.id == undefined
            api.post('rest/vabc/tipoff/save', postData).then(res => {
              this.$message.success('创建成功')
              this.reset()
              this.visible = false
              this.$parent.getDataList()
            }).finally(() => {
              this.loading = false
            })
          } else {
            postData.status=1;
            api.post('rest/vabc/tipoff/update', postData).then(res => {
              this.$message.success('保存成功')
              this.reset()
              this.visible = false
              this.$parent.getDataList()
            }).finally(() => {
              this.loading = false
            })
          }
        }
      })
    },
    cancel() {
      this.visible = false
      this.reset()
    },
    reset() {
      this.$refs.dataForm.resetFields()
      this.$data.dataForm = JSON.parse(JSON.stringify(this.$options.data().dataForm))
      //图片回写
      //this.$refs["childData"].fileList=[]
    }
  }
}
</script>
